package com.jmb.apiplatform.controller;


import com.jmb.apiplatform.common.PageResult;
import com.jmb.apiplatform.common.Result;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.pojo.ModuleDao;
import com.jmb.apiplatform.pojo.ModuleVO;
import com.jmb.apiplatform.service.ModuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "模块管理")
@Slf4j
@RequestMapping("/module")
@RestController()
public class ModuleController {
    @Autowired
    private ModuleService moduleService;

    @Operation(summary = "新增模块")
    @PostMapping("/save")
    public Result saveModule(@RequestBody ModuleDao moduleDao) throws ValidException {
        moduleService.saveModule(moduleDao);
        return Result.success("新增成功");
    }
    @Operation(summary = "模块列表")
    @GetMapping("/list")
    public Result pageList( ModuleVO moduleVO){
        PageResult<ModuleDao> pageResult = moduleService.listModel(moduleVO);
        return Result.success(pageResult);
    }
    @Operation(summary = "删除模块")
    @GetMapping("/remove/{id}")
    public Result removeById(@PathVariable Integer id) throws ValidException {
        moduleService.removeById(id);
        return Result.success("删除成功");
    }

    @Operation(summary = "查找模块")
    @GetMapping("/{id}")
    public Result finModuleId(@PathVariable Integer id) throws ValidException {
        ModuleDao moduleDao = moduleService.finModuleId(id);
        return Result.success(moduleDao);
    }
    @Operation(summary = "修改模块")
    @PostMapping("/modify")
    public Result modifyUpdate(@RequestBody ModuleDao moduleDao) throws ValidException {
        moduleService.updateModule(moduleDao);
        return Result.success("修改成功");
    }
}
